﻿using System;
using System.Collections.Generic;

namespace MSDNWebcast.Service
{
    public class ServiceFactory
    {
        public ServiceFactory()
        {
            objList = new Dictionary<Type, object>();
        }

        internal void InjectServices(List<object> services)
        {
            foreach (object obj in services)
            {
                objList.Add(obj.GetType(), obj);
            }
        }

        public T GetService<T>() where T : class
        {
            return this.objList[typeof(T)] as T;
        }

        private Dictionary<Type, object> objList;

        private static ServiceFactory s_Instance;

        public static ServiceFactory Instance
        {
            get
            {
                if (s_Instance == null)
                    s_Instance = new ServiceFactory();
                return s_Instance;
            }
        }
    }
}
